package com.suray.basic.wcs.plc.pojo.oper;

import com.suray.basic.wcs.plc.core.PlcOffset;
import com.suray.basic.wcs.plc.enums.PlcDeviceType;
import com.suray.basic.wcs.plc.enums.Location;
import com.suray.basic.wcs.plc.pojo.DeviceBase;
import com.suray.basic.wcs.utils.Coord;

/**
 * @author shaozn
 * @date 2020/1/22 - 16:11
 * @Description 自动门
 */
public class AutomaticDoorOper extends DeviceBase {
    private static final PlcOffset IS_OPEN = new PlcOffset(0, 8);
    private static final PlcOffset IS_CLOSE = new PlcOffset(0, 9);
    private static final PlcOffset IS_ERROR = new PlcOffset(0, 10);

    /**
     * 自动门已开启
     */
    private boolean isOpen;
    /**
     * 自动门已关闭
     */
    private boolean isClose;
    /**
     * 自动门故障
     */
    private boolean isError;

    public AutomaticDoorOper(PlcDeviceType plcDeviceType, int startNo, String deviceName, int deviceNo, Coord coord,
                             Location location, Coord lockLocation, long deviceId, Integer gridzMax,
                             Integer gridzRelative, int plcId) {
        super(plcDeviceType, startNo, deviceName, deviceNo, coord, location, lockLocation,deviceId,gridzMax,
                gridzRelative, plcId);
    }


    public boolean isOpen() {
        return readPlc(IS_OPEN) == 1;
    }

    public boolean isClose() {
        return readPlc(IS_CLOSE) == 1;
    }

    public boolean isError() {
        return readPlc(IS_ERROR) == 1;
    }

    public void setOpen(boolean open) {
        isOpen = open;
    }

    public void setClose(boolean close) {
        isClose = close;
    }

    public void setError(boolean error) {
        isError = error;
    }
}
